home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / PT.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  18KB  |  639 lines

  1. #include "pt.h"
  2. #include "direct.h"
  3. #include "malloc.h"
  4. #include "string.h"
  5. #include "conio.h"
  6. #include "io.h"
  7. #include "process.h"
  8. #include "stdlib.h"
  9. #include "time.h"
  10.  
  11. extern void criterr(void);
  12. extern void overlay(int);
  13.  
  14. void
  15. /* XTAG:main */
  16. main(argc, argv)
  17.     unsigned char *argv[];
  18. {
  19.  
  20. /**************************************************************************/
  21. /*   Declare the external variables                                       */
  22. /**************************************************************************/
  23.  
  24.     extern struct window *windows, *windowList;
  25.     extern unsigned char msgBuffer[];
  26.     extern unsigned char startDirectory[];
  27.     extern unsigned char currentDirectory[];
  28.     extern unsigned char startDrive;
  29.     extern unsigned char currentDrive;
  30.     extern unsigned char scrMapReset;
  31.     extern unsigned int dispMemory;
  32.     extern int debug;
  33.     extern union REGS rin, rout;
  34.     extern struct window *selWindow;
  35.     extern long selBegin, selEnd;
  36.     extern int selMode;
  37.     extern int undoSize;
  38.     extern int nextChange;
  39.     extern int addHandle;
  40.     extern unsigned char addFile[];
  41.     extern long addPosition;
  42.     extern int brIntCom[];
  43.     extern int initialWindows;
  44.     extern struct changeItem scrapBuffer;
  45.     extern struct SREGS segRegs;
  46.     extern unsigned char saveVideoMode;
  47.     extern int scrRows, scrCols;
  48.     extern unsigned char filePattern[];
  49.     extern unsigned char tagPattern[];
  50.     extern unsigned char tagMarker[];
  51.     extern struct window *activeWindow;
  52.     extern int menuLine;
  53.     extern int descrFileId;
  54.     extern jmp_buf breakEnv;
  55. #ifdef OVERLAYS
  56.     extern int overlayVector;
  57. #endif
  58.     extern int readOnly;
  59.     extern int supressFileMsgs;
  60.     extern struct menuBlock far *menus[];
  61.     extern unsigned char *copyRightMsg;
  62.     extern unsigned char *userMessages[];
  63.     extern unsigned char far * fileHandleTable;
  64.     extern int maxFiles;
  65.     extern struct openFile *files;
  66.     extern time_t timeOfLastSave;
  67.     extern unsigned char far *menuSpace;
  68.  
  69. /**************************************************************************/
  70. /*   Declare the local variables                                          */
  71. /**************************************************************************/
  72.  
  73.     int i, j, k, row, col, where;
  74.     int deltaRow, deltaCol, nWindows, topMode;
  75.     unsigned char *p;
  76.     unsigned int far * fp;
  77.     unsigned char far * oldTable;
  78.     struct window *w;
  79.     int lastState = 0;    /* restore the last state of the editor */
  80.     int hideFiles;
  81.  
  82. /**************************************************************************/
  83. /*   Save the old video mode and set a compatible video mode to use       */
  84. /**************************************************************************/
  85.  
  86. /* determine the current display mode */
  87. rin.h.ah = 15;
  88. int86(0x10, &rin, &rout);
  89. saveVideoMode = rout.h.al;
  90.  
  91. switch( saveVideoMode ) {
  92. case 7:    /* monochrome display */
  93.     dispMemory = 0xB000;
  94.     break;
  95. case 4:    /* 320x200 color */
  96.     rin.h.al = 3;    /* 80x25 color */
  97.     goto setMode;
  98. case 5:    /* 320x200 b&w */
  99. case 6:    /* 640x200 b&w */
  100.     rin.h.al = 2;    /* 80x25 b&w */
  101. setMode:
  102.     rin.h.ah = 0;    /* set video mode */
  103.     int86(0x10, &rin, &rout);
  104. default:
  105.     dispMemory = 0xB800;
  106.     break;
  107. }
  108.  
  109. /* get the segment registers */
  110. segread(&segRegs);
  111.  
  112. /**************************************************************************/
  113. /*   Get the current directory and drive so we can restore then on exit   */
  114. /**************************************************************************/
  115. (void)getcwd(&startDirectory[0], FILENAMESIZE);
  116. strcpy(currentDirectory, startDirectory);
  117. startDrive = getDefaultDrive();
  118. currentDrive = startDrive;
  119.  
  120. /**************************************************************************/
  121. /*   Read in the initialization file but first                            */
  122. /*    set the variables it might change from their default values         */
  123. /**************************************************************************/
  124.  
  125. /* set up the menu blocks */
  126.  
  127. /* This one is for dynamic menus (OPTIONS and TOPLIST and HELP) */
  128. menus[0] = (struct menuBlock far *)_fmalloc(sizeof(struct menuBlock));
  129.  
  130. /* initialize the other menus to not yet allocated */
  131. for(i = 1; i < NMENUS; ++i)
  132.     menus[i] = (struct menuBlock far *)NULL;
  133.  
  134. /* set up space for the menu characters */
  135. menuSpace = (unsigned char far *)_fmalloc(MENUSPACE);
  136.  
  137. /* set up variables */
  138. addFile[0] = '\0';
  139. strcpy(filePattern, "*.*");
  140. strcpy(tagPattern, "*.c|*.h|*.asm");
  141. strcpy(tagMarker, "XTAG:");
  142.  
  143. /* set up the default asciiMap so that setup can alter it */
  144. initKeymaps();
  145.  
  146. /* read the setup file */
  147. if( setup() ) {
  148.     cprintf(
  149.     "Cannot find \"pt.ini\" in this directory or the PATH.\r\nExiting.\r\n");
  150.     exit(1);
  151. }
  152.  
  153. /**************************************************************************/
  154. /*   Allocate a new file handle table to allow more than 20 open files    */
  155. /*   then allocate the open file table and the window structures          */
  156. /**************************************************************************/
  157. if( _osmajor == 3 ) {    /* only works for DOS 3.x */
  158.     if( 0 <= _osminor && _osminor <= 20 ) {
  159.         /* version 3.00, 3.10, and 3.20 only */
  160.         /* allocate space for the file handles */
  161.         fileHandleTable = (unsigned char far *)_fmalloc(maxFiles);
  162.         /* find the current file handle table in the PSP */
  163.         FP_OFF(fp) = 0x32;    /* at 0x32 in PSP */
  164.         FP_SEG(fp) = _psp;
  165.         row = *fp;    /* get the size of the current table */
  166.         FP_OFF(oldTable) = *(fp+1);    /* addr of current table */
  167.         FP_SEG(oldTable) = *(fp+2);
  168.         /* copy current table to new table */
  169.         for(i = 0; i < row; ++i )
  170.             fileHandleTable[i] = oldTable[i];
  171.         /* mark the rest of the handles in the new table */
  172.         /* as unopened (0xFF) */
  173.         for(i = row; i < maxFiles; ++i)
  174.             fileHandleTable[i] = 0xFF;
  175.         /* install the new table by changing the PSP fields */
  176.         *fp = (unsigned int)maxFiles;
  177.         *(fp+1) = FP_OFF(fileHandleTable);
  178.         *(fp+2) = FP_SEG(fileHandleTable);
  179.     } else if( _osminor >= 30 ) {
  180.         /* we can do the same thing wiht a simple DOS call! */
  181.         rin.h.ah = 0x67;    /* set handle count */
  182.         /* Steve Gibson's TSR example added the +1 so I am too */
  183.         /* just to be sure that I get enough handles */
  184.         rin.x.bx = maxFiles + 1;
  185.         intdos(&rin, &rout);
  186.     } else
  187.         maxFiles = 20;
  188. } else
  189.     maxFiles = 20;
  190.  
  191. /* allocate an extra file structure for use in copymove.c (insScrap) */
  192. files = (struct openFile *)malloc((maxFiles+1) * sizeof(struct openFile));
  193. windows = (struct window *)malloc(maxFiles * sizeof(struct window));
  194. if( files == NULL || windows == NULL) {
  195.     cprintf("Too many files (out of memory). Reduce maxFiles\r\n");
  196.     exit(1);
  197. }
  198.  
  199. /**************************************************************************/
  200. /*   call various initialization routines                                 */
  201. /**************************************************************************/
  202.  
  203. initWindows();
  204. initFileio();
  205. initChanges();
  206.  
  207. /**************************************************************************/
  208. /*   Process the command line options and arguments                       */
  209. /**************************************************************************/
  210.  
  211. for(i = 1; i < argc; i++) {
  212.     if( argv[i][0] == '/' || argv[i][0] == '-' ) {
  213.         for(j = 1; argv[i][j] != '\0'; j++) {
  214.             switch( argv[i][j] ) {
  215.  
  216.             case 'l':  /* restore last state */
  217.                 lastState = 1;
  218.                 break;
  219.  
  220.             case 'o':  /* overlaid windows */
  221.                 initialWindows = 0;
  222.                 break;
  223.  
  224.             case 'h':  /* horizontal split */
  225.                 initialWindows = 1;
  226.                 break;
  227.  
  228.             case 'v':  /* vertical split */
  229.                 initialWindows = 2;
  230.                 break;
  231.  
  232.             case 'r':  /* read only mode */
  233.                 readOnly = 1;
  234.                 break;
  235.  
  236.             case 'd':  /* debug flag initial value */
  237.                 debug = argv[i][++j] - '0';
  238.                 break;
  239.  
  240.             default:
  241.                 cprintf("usage: pt [/hlov] [file1] [file2] ...\r\n");
  242.                 break;
  243.             }
  244.         }
  245.     } else    /* we have reached the end of the comamnd line options */
  246.         break;
  247. }
  248.  
  249. initMouse(5, 10, 1);
  250.  
  251. /* clear the screen */
  252. scrollUp(0, 0, 0, scrRows-1, scrCols-1, 0x7);
  253.  
  254. /**************************************************************************/
  255. /*   create the menu line